using UnityEngine;

public class MoveBehaviour
{
    public float speedMax;
    public float speedIncrement;
    public float speedTimeInterval;
    private Vector3 speed;
    private MoveableObject moveableObject;
    private float timeIncreased;

    public MoveBehaviour(MoveableObject _moveableObject)
    {
        moveableObject = _moveableObject;
    }

    public void init(MoveParams _moveParams)
    {
        speedMax = _moveParams.SpeedMax;
        speedIncrement = _moveParams.SpeedIncrement;
        speedTimeInterval = _moveParams.SpeedTimeInterval;
        speed = _moveParams.Speed;        
    }

    public void move(float deltaTime)
    {
        moveableObject.transform.localPosition += (speed * deltaTime);
    }

    public void update(float deltaTime)
    {
        updateTimeIncreased(deltaTime);

        if (timeIncreased > speedTimeInterval)
        {
            resetTimeIncreased();
            incrementSpeed();
        }
    }

    private void updateTimeIncreased(float deltaTime)
    {
        timeIncreased += deltaTime;
    }

    private void resetTimeIncreased()
    {
        timeIncreased = 0;
    }

    private void incrementSpeed()
    {
        if (speed.x <= speedMax)
            speed.x += -speedIncrement;
    }
}